package com.moshang.blog.quartz.job;

import com.moshang.blog.core.utils.SpringUtils;
import com.moshang.blog.service.TbArticleInfoService;
import com.moshang.blog.service.TblGreatService;
import com.moshang.blog.service.impl.TbArticleInfoServiceImpl;
import com.moshang.blog.service.impl.TblGreatServiceImpl;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 点赞相关功能定时任务
 * Created on 2019/4/25.
 */
@Transactional
public class LikeTask implements Job {
    @Autowired
    private TbArticleInfoService tbArticleInfoService;
    @Autowired
    private TblGreatService tblGreatService;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        //System.out.println("JobDemo1：启动任务=======================");
        run();
  /*System.out.println("JobDemo1：下次执行时间====="+
        new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
            .format(context.getNextFireTime())+"==============");*/
    }

    public void run(){
//        ApplicationContext applicationContext= SpringUtils.getApplicationContext();
        System.out.println("点赞持久化：开始执行=======================");
        //可以 获取
//           TblGreatService tblGreatService= SpringUtils.getBean(TblGreatServiceImpl.class);
//        TbArticleInfoService tbArticleInfoService=SpringUtils.getBean(TbArticleInfoServiceImpl.class);
           tblGreatService.saveDb();
           tbArticleInfoService.saveCountDb();
//        List<SysUser> userList=sys.selectListByPage(new SysUser());
        //System.out.println(userList.get(0).getUsername());;
        System.out.println("点赞持久化：执行完毕=======================");

    }
}
